
package com.udc.medLine.transaction;

import java.util.List;

import com.udc.medLine.entity.CondicaoVO;
import com.udc.medLine.entity.Funcionario;
import com.udc.medLine.entity.Laboratorio;
import com.udc.medLine.factory.FactoryFuncionario;
import com.udc.medLine.factory.FactoryLaboratorio;
import com.udc.medLine.persistence.Bd;

public class TransactionLaboratorio {

	private Laboratorio laboratorio;
	private List listLaboratorio;
	private Bd banco;
	
	/**
	 * 
	 */
	public TransactionLaboratorio() {
		super();
		laboratorio = new Laboratorio();
		try{
			banco = Bd.getInstance();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		// TODO Stub de construtor gerado automaticamente
	}

	public Laboratorio getLaboratorio() {
		return laboratorio;
	}

	public void setLaboratorio(Laboratorio new_laboratorio) {
		this.laboratorio = new_laboratorio;
	}

	public void remover(Laboratorio nLaboratorio) throws Exception {
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();
			laboratorio.setId(nLaboratorio.getId());
			factory.setLaboratorio(laboratorio);
			factory.delete();
		banco.commit();
	}

	public void inserir(Laboratorio nLaboratorio) throws Exception {
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();			
			laboratorio.setNome(nLaboratorio.getNome());
			factory.setLaboratorio(laboratorio);
			factory.insert();
		banco.commit();
	}

	public void atualizar(Laboratorio nLaboratorio) throws Exception {
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();
			laboratorio.setId(nLaboratorio.getId());
			laboratorio.setNome(nLaboratorio.getNome());
			factory.setLaboratorio(laboratorio);
			factory.update();
		banco.commit();
	}


	public void obterLaboratorio(String campo, String valor) throws Exception{
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();
			factory.setLaboratorio(new Laboratorio());
			listLaboratorio = factory.getLaboratorio(campo,valor);
		banco.commit();
	}
	
	public void obterListaLaboratorio() throws Exception{
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();
			factory.setLaboratorio(new Laboratorio());
			listLaboratorio = factory.getListaLaboratorio();
		banco.commit();
	}
	
	public void obterLaboratorio(Laboratorio nLaboratorio) throws Exception{
		banco.beginTransaction();
			FactoryLaboratorio factory = new FactoryLaboratorio();
			laboratorio.setId(nLaboratorio.getId());
			factory.setLaboratorio(laboratorio);
			laboratorio = factory.obterLaboratorio();
		banco.commit();
	}
	
	/**
	 * @return
	 */
	public List getListLaboratorio() {
		return listLaboratorio;
	}

	/**
	 * @param list
	 */
	public void setListLaboratorio(List list) {
		listLaboratorio = list;
	}

	public List<Laboratorio> search(CondicaoVO condicao) throws Exception {
		banco.beginTransaction();
		FactoryLaboratorio factory = new FactoryLaboratorio();
		listLaboratorio = factory.search(condicao);
		banco.commit();
		return listLaboratorio;
	}

}
